<?php
include("../../Connections/connect_client.php");
$id=intval($_POST["id"]);
$name=$_POST["name"];
$email=$_POST["email"];
$content=$_POST["content"];
if($name=='')
{
	$res= array(
				   'ok'=>false,
				   'msg'=>'Your name is not empty'
				   );
echo json_encode($res);
}
else if($email=='')
{
	$res= array(
				   'ok'=>false,
				   'msg'=>'Email is not empty'
				   );
echo json_encode($res);
}
else if($content=='')
{
	$res= array(
				   'ok'=>false,
				   'msg'=>'Content is not empty'
				   );
echo json_encode($res);
}
else if(!preg_match( "/^[A-z0-9_]+([.][A-z0-9_]+)*[@][A-z0-9_]+([.][A-z0-9_]+)*[.][A-z]{2,4}$/", $email))
{
	$res= array(
				   'ok'=>false,
				   'msg'=>'Please to enter a valid email'
				   );
echo json_encode($res);
}
else
{
$query="INSERT INTO `comment`(NewsID,Content,AuthorName,Email)VALUES($id,'$content','$name','$email')";
if(mysql_query($query))
{
	$date=date("d/m/Y");
	$html="<div class='comment'><strong>$name</strong>&nbsp;($date)<div>$content</div></div>";
	$res= array(
				   'ok'=>true,
				   'html'=>$html
				   );
	echo json_encode($res);
}
}

?>